package flc.ast.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;

import com.stark.more.MorePrefUtil;
import com.stark.more.MoreUiUtil;

import flc.ast.BaseAc;
import flc.ast.R;
import flc.ast.databinding.ActivitySettingBinding;
import stark.common.basic.event.usersys.UserSysEventProxy;

public class SettingActivity extends BaseAc<ActivitySettingBinding> {


    @Override
    protected int onCreate() {
        return R.layout.activity_setting;
    }

    @Override
    protected void initView() {
        mDataBinding.ivSettingBack.setOnClickListener(v -> onBackPressed());

        mDataBinding.ivSettingsRecom.setOnClickListener(this);
        mDataBinding.rlUserCenter.setOnClickListener(this);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()){
            case R.id.ivSettingsRecom:
                boolean isOpened= MoreUiUtil.isPersonalRecommendOpened();
                MoreUiUtil.setPersonalRecommendOpened(!isOpened);
                if (isOpened){
                    mDataBinding.ivSettingsRecom.setImageResource(R.drawable.aguan);
                }else{
                    mDataBinding.ivSettingsRecom.setImageResource(R.drawable.akai);
                }
                break;
            case R.id.rlUserCenter:
                UserSysEventProxy.getInstance().goUserCenter(this);
                break;
        }
    }

    @Override
    protected void initData() {
        boolean isOpened = MoreUiUtil.isPersonalRecommendOpened();
        if (isOpened) {
            //将控件开关设为开
            mDataBinding.ivSettingsRecom.setImageResource(R.drawable.akai);
        } else {
            //将控件开关设为关
            mDataBinding.ivSettingsRecom.setImageResource(R.drawable.aguan);
        }
        boolean showPersonalRecommend = MorePrefUtil.showPersonalRecommend();
        if (showPersonalRecommend) {
            //显示个性化开关控件
            mDataBinding.rlSettingsRecom.setVisibility(View.VISIBLE);
        } else {
            //隐藏个性化开关控件
            mDataBinding.rlSettingsRecom.setVisibility(View.GONE);
        }
        mDataBinding.rlUserCenter.setVisibility(UserSysEventProxy.getInstance().supportUserSys()?View.VISIBLE:View.GONE);
    }
}